<template>
  <div class="draft-box">
    <MyHeader>
      <div slot="title">
        草稿箱
      </div>
    </MyHeader>
    <div class="refresh-draft-box" @click="refresh">
      刷新草稿箱
    </div>
    <div class="draft-box-list">
      <div v-if="artWorkList.length > 0" class="content clearfix" v-for="(item, index) in artWorkList" :key="index">
        <el-image :src="item.thumbnail" fit="cover" alt="" />
        <div class="right-content">
          <div class="title">
            {{ item.name }}
          </div>
          <!-- <div class="type-name">
            {{ item.quality }}
          </div> -->
          <div class="time">
            {{ '上次修改时间：' + item.create_time }}
          </div>
        </div>
        <div class="btn">
          <div @click="workEdit(item.data_id, item.work_type)" class="edit all-center">
            编辑
          </div>
          <div @click="deleteWorks(item.data_id)" class="delete all-center">
            删除
          </div>
        </div>
      </div>
      <el-empty v-if="artWorkList.length == 0" style="margin: 0 auto" description="暂无数据"></el-empty>
    </div>
    <Pagin
      ref="page"
      v-show="artWorkList.length !== 0"
      :func="getDataList"
      :pagesSizes="[10, 20, 30, 50]"
      :sizeNum="10"
      :layout="'prev, pager, next'"
      background
      :position="'center'"
      class="pagin"
    ></Pagin>
  </div>
</template>

<script>
import Pagin from '@/components/pagin.vue'
// import artWorkList from './artWorkList.js'
import MyHeader from './common/myHeader.vue'
export default {
  name: '',
  middleware: 'identityInfo',
  components: {
    Pagin,
    MyHeader
  },
  props: {},
  data () {
    return {
      artWorkList: []
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {
    this.refresh()
  },
  methods: {
    refresh() {
      this.refresh()
    },
    workEdit(data_id, work_type) {
      console.log('去编辑')
      if (work_type == 2) {
        this.$emit('goWorks', 1, data_id)
        // this.$router.push({
        //   path: "/editPersonalHome/uploadVideos",
        //   query: {
        //     data_id
        //   },
        // })
      } else {
        this.$emit('goWorks', 0, data_id)
        // this.$router.push({
        //   path: "/editPersonalHome/uploadWorks",
        //   query: {
        //     // 携带参数
        //     data_id
        //   },
        // });
      }
    },
    deleteWorks(data_id) {
      this.$api.deleteArtWorks({ data_id }).then(res => {
        if (res.status === '$SUCCESS') {
          this.$message.success('删除成功')
          this.refresh()
        }
      })
    },
    getDataList(page, page_size, callback) {
      // 这里要写接口然后把数据和total丢进去
      this.$api
      .getWorksList({
        // work_type: 1,
        recycle: 1,
        art_id: this.$store.state.user.info?.user_info?.art_info?.data_id,
        page_num: page,
        page_count: page_size,
      })
      .then((res) => {
        this.artWorkList = Array.isArray(res.result.item_list)
          ? res.result.item_list
          : [];
          console.log('res',this.artWorkList)

        callback(this.artWorkList, this.artWorkList.length);
      });
    },
    refresh() {
      this.$refs.page.refresh()
    }
  }
}
</script>

<style scoped lang="less">
.draft-box {
  background: #fff;
  padding-bottom: 40px;
  position: relative;

  .refresh-draft-box {
    padding: 10px;
    background-color: #e0cbb4;
    border: 1px solid #e0cbb4;
    position: absolute;
    top: 10px;
    right: 30px;
    cursor: pointer;
  }

  .draft-box-list {
    padding: 40px 29px 12px 48px;

    .content {
      position: relative;
      margin-bottom: 48px;

      ::v-deep(.el-image) {
        width: 320px;
        height: 214px;
        margin-right: 48px;
        float: left;
      }

      .right-content {
        float: left;
        font-size: 16px;
        font-weight: 600;
        color: #999;
        line-height: 16px;

        .title {
          color: #000;
          margin-bottom: 24px;
        }

        .type-name {
          margin: 24px 0;
        }
      }

      .btn {
        position: absolute;
        right: 0;
        top: 0;
        font-size: 16px;
        color: #000;

        .edit,
        .delete {
          display: flex;
          width: 165px;
          height: 42px;
          border: 1px solid #E8E8E8;
          margin-bottom: 38px;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
